package com.github.kezhenxu94.playground.java.atoffer;

/**
*
* 替换空格
* 
* 请实现一个函数，将一个字符串的空格替换成"%20"
* 
* 例如，当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy
*/
public class AtOfferReplaceSpace {

	public static void main(String[] args) {
		AtOfferReplaceSpace sol = new AtOfferReplaceSpace();
		System.out.println(sol.replaceSpace(new StringBuffer("Hello world")));
	}

	public String replaceSpace(StringBuffer str) {
		while (str.indexOf(" ") > 0) {
			int index = str.indexOf(" ");
			str.replace(index, index + 1, "%20");
		}
		return str.toString();
	}
}